<template>
<!--科目查询卡片-->
  <el-card style="height: 70px;margin: 10px">
    <el-form :inline="true">
      <el-form-item label="课程名称" style="width: 270px; float: left;" >
        <el-input placeholder="请输入课程"
                  v-model="searchSubjectForm.name" @keydown.enter="loadSubject"></el-input>
      </el-form-item>
      <el-form-item style="float: left">
        <el-button type="primary" @click="loadSubject">查询</el-button>
        <el-button @click="resetSearch">重置</el-button>
      </el-form-item>
      <el-button type="danger" style="float: right;"
                 @click="beforeAddSubject">添加科目</el-button>
    </el-form>
  </el-card>
<!--科目表格-->
  <el-card style="margin: 10px">
    <el-table :data="subjectsArr">
      <el-table-column type="index" label="ID" align="center" width="80">

      </el-table-column>
      <el-table-column type="subject" label="科目名称" align="center"></el-table-column>
      <el-table-column type="introduce" label="介绍" align="center" ></el-table-column>
      <el-table-column label="操作" align="center" >
        <template #default="scope">
          <el-button type="primary" link
                     @click="editSubejct(scope.row.id)">编辑</el-button>
          <el-button type="danger" link
                      @click="deleteSubject(scope.row.id)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
  </el-card>

</template>


<script setup>
import {onMounted, ref} from "vue";
import axios from "axios";
import qs from "qs";
import {ElMessage} from "element-plus";

const searchSubjectForm = ref({name: "",introduce:""});
const subjectsArr = ref([]);
onMounted(()=>{
  loadSubject();
});
const loadSubject = () => {
  let data = qs.stringify(searchSubjectForm.value);
  axios.get(BASE_URL+"/v1/subject/select?"+data).then((response)=>{
    if (response.data.code == 2000){
      subjectsArr.value=response.data.data;
      console.log(subjectsArr.value)
    }else {
      ElMessage.error(response.data.message);
    }
  })
}


</script>


<style scoped>

</style>